/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewLogin.java
 *
 * Created on 26.10.2009, 23:29:44
 */

package twitt;

import org.jdesktop.application.Action;
import TwitterClient.TwitterWrap;


/**
 *
 * @author Sad_hamster
 */
public class NewLogin extends javax.swing.JDialog {

    /** Creates new form NewLogin */
    public NewLogin(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        setTitle("Login Box");
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonOk = new javax.swing.JButton();
        jlbLogin = new javax.swing.JLabel();
        jLbPass = new javax.swing.JLabel();
        jtfLogin = new javax.swing.JTextField();
        jButtonExit = new javax.swing.JButton();
        jtProxyAddres = new javax.swing.JTextField();
        jtProxyUserName = new javax.swing.JTextField();
        jtProxyPort = new javax.swing.JTextField();
        cbProxy = new javax.swing.JCheckBox();
        jlProxyPort = new javax.swing.JLabel();
        jlUName = new javax.swing.JLabel();
        jlUPassword = new javax.swing.JLabel();
        jtfPassword = new javax.swing.JPasswordField();
        jtProxyUserPassword = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(twitt.TwittApp.class).getContext().getActionMap(NewLogin.class, this);
        jButtonOk.setAction(actionMap.get("AceptData")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(twitt.TwittApp.class).getContext().getResourceMap(NewLogin.class);
        jButtonOk.setText(resourceMap.getString("jButtonOk.text")); // NOI18N
        jButtonOk.setName("jButtonOk"); // NOI18N

        jlbLogin.setText(resourceMap.getString("jlbLogin.text")); // NOI18N
        jlbLogin.setName("jlbLogin"); // NOI18N

        jLbPass.setText(resourceMap.getString("jLbPass.text")); // NOI18N
        jLbPass.setName("jLbPass"); // NOI18N

        jtfLogin.setName("jtfLogin"); // NOI18N

        jButtonExit.setAction(actionMap.get("Exit")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jtProxyAddres.setText(resourceMap.getString("jtProxyAddres.text")); // NOI18N
        jtProxyAddres.setName("jtProxyAddres"); // NOI18N

        jtProxyUserName.setText(resourceMap.getString("jtProxyUserName.text")); // NOI18N
        jtProxyUserName.setName("jtProxyUserName"); // NOI18N

        jtProxyPort.setText(resourceMap.getString("jtProxyPort.text")); // NOI18N
        jtProxyPort.setName("jtProxyPort"); // NOI18N

        cbProxy.setAction(actionMap.get("chackUseProxy")); // NOI18N
        cbProxy.setText(resourceMap.getString("cbProxy.text")); // NOI18N
        cbProxy.setName("cbProxy"); // NOI18N

        jlProxyPort.setText(resourceMap.getString("jlProxyPort.text")); // NOI18N
        jlProxyPort.setName("jlProxyPort"); // NOI18N

        jlUName.setText(resourceMap.getString("jlUName.text")); // NOI18N
        jlUName.setName("jlUName"); // NOI18N

        jlUPassword.setText(resourceMap.getString("jlUPassword.text")); // NOI18N
        jlUPassword.setName("jlUPassword"); // NOI18N

        jtfPassword.setText(resourceMap.getString("jtfPassword.text")); // NOI18N
        jtfPassword.setName("jtfPassword"); // NOI18N

        jtProxyUserPassword.setText(resourceMap.getString("jtProxyUserPassword.text")); // NOI18N
        jtProxyUserPassword.setName("jtProxyUserPassword"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLbPass)
                            .addComponent(jlbLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfLogin, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
                            .addComponent(jtfPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jlProxyPort)
                                    .addComponent(jlUName)
                                    .addComponent(jlUPassword)
                                    .addComponent(cbProxy))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtProxyUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .addComponent(jtProxyAddres, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .addComponent(jtProxyUserPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButtonOk, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(14, 14, 14))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlbLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLbPass)
                    .addComponent(jtfPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtProxyAddres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlProxyPort)
                    .addComponent(jtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtProxyUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlUName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlUPassword)
                    .addComponent(jtProxyUserPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbProxy)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonOk, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jtProxyAddres.setVisible(cbProxy.isSelected());
        jtProxyUserName.setVisible(cbProxy.isSelected());
        jtProxyPort.setVisible(cbProxy.isSelected());
        cbProxy.setText("Use proxy");
        jlProxyPort.setText("Proxy & port");
        jlProxyPort.setVisible(cbProxy.isSelected());
        jlUName.setText("User name");
        jlUName.setVisible(cbProxy.isSelected());
        jlUPassword.setText("User password");
        jlUPassword.setVisible(cbProxy.isSelected());
        jtProxyUserPassword.setVisible(cbProxy.isSelected());

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                NewLogin dialog = new NewLogin(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
                dialog.setBounds(dialog.getLocation().x, dialog.getLocation().y, dialog.getWidth(), 165);
            }
        });
    }

  @Action
  public void AceptData() {
    TwitterWrap tw = new TwitterWrap();
    tw.SetLogin(jtfLogin.getText());
    tw.SetPassword(new String(jtfPassword.getPassword()));

    if (cbProxy.isSelected()) {
      tw.SetProxyAddres(jtProxyAddres.getText());
      tw.SetProxyPort(Integer.parseInt(jtProxyPort.getText()));
      tw.SetProxyUserName(jtProxyUserName.getText());
      tw.SetProxyUserPassword(new String(jtProxyUserPassword.getPassword()));
    }

    this.setVisible(false);
  }

  @Action
  public void Exit() {
    TwitterWrap tw = new TwitterWrap();
    tw.SetLogin(jtfLogin.getText());
    tw.SetPassword(new String(jtfPassword.getPassword()));
    setVisible(false);
  }

  @Action
  public void chackUseProxy() {
    boolean isSelected = cbProxy.isSelected();
    jtProxyAddres.setVisible(isSelected);
    jtProxyPort.setVisible(isSelected);
    jtProxyUserName.setVisible(isSelected);
    jtProxyUserPassword.setVisible(isSelected);
    jlProxyPort.setVisible(isSelected);
    jlUName.setVisible(isSelected);
    jlUPassword.setVisible(isSelected);

    if (isSelected) {
      this.setBounds(this.getLocation().x, this.getLocation().y, this.getWidth(), 225);
    } else {this.setBounds(this.getLocation().x, this.getLocation().y, this.getWidth(), 165);}
    this.repaint();

  }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox cbProxy;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonOk;
    private javax.swing.JLabel jLbPass;
    private javax.swing.JLabel jlProxyPort;
    private javax.swing.JLabel jlUName;
    private javax.swing.JLabel jlUPassword;
    private javax.swing.JLabel jlbLogin;
    private javax.swing.JTextField jtProxyAddres;
    private javax.swing.JTextField jtProxyPort;
    private javax.swing.JTextField jtProxyUserName;
    private javax.swing.JPasswordField jtProxyUserPassword;
    private javax.swing.JTextField jtfLogin;
    private javax.swing.JPasswordField jtfPassword;
    // End of variables declaration//GEN-END:variables

}
